#pragma once
#include <unistd.h>
#include <string>

const std::string opers="+-*%(!";

class Task
{
public:
    Task()
    {
    }
    Task(int x, int y, char op)
        : _x(x), _y(y), _op(op), _code(0), _ret(0)
    {
    }

    void Run()
    {
        switch (_op)
        {
        case '+':
            _ret = _x + _y;
            break;
        case '-':
            _ret = _x - _y;
            break;
        case '*':
            _ret = _x * _y;
            break;
        case '/':
            if (!_y)
            {
                _code = 1;
                break;
            }
            _ret = _x / _y;
            break;
        default:
            _ret=-1;
            _code = 2; // 表示未识别的字符
            break;
        }
    }

    void operator()()
    {
        Run();
    }

    std::string PrintTask()
    {
        std::string ret = std::to_string(_x);
        ret += " ";
        ret+=_op;
        ret+=" ";
        ret += std::to_string(_y) + " = ? ";
        return ret;
    }

    std::string PrintResult()
    {
        std::string ret = std::to_string(_x);
        ret += " ";
        ret+=_op;
        ret+=" ";
        ret += std::to_string(_y) + " = ";
        ret += std::to_string(_ret);
        ret += " [";
        ret+=std::to_string(_code);
        ret+=+"] ";
        return ret;
    }

private:
    char _op;
    int _x;
    int _y;

    int _ret;
    int _code;
};